var isPalindrome = function(head) {
    var reverseHead = [];
    while (head != null) {
        reverseHead.push(head.val);
        head = head.next;
    }
    for (let i = 0, j = reverseHead.length - 1; i < j; i++, j--) {
        if (reverseHead[i] !== reverseHead[j]) {
            return false;
        }
    }
    return true;
}